package com;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * The type Aspect anno.
 */
@Aspect
@Component
public class AspectAnno {
    /**
     * Point cut.
     */
    @Pointcut("execution(* com.service.impl.*.*(..))")
    public void pointCut(){

    }

    /**
     * My before.
     *
     * @param joinPoint the join point
     */
    @Before("pointCut()")
    public void myBefore(JoinPoint joinPoint){
        System.out.println("------------");
        System.out.println("这是前置通知:日志开始打印..");
        System.out.println("目标类是:"+joinPoint.getTarget());
        System.out.println("目标类方法是:"+joinPoint.getSignature().getName());
    }

    /**
     * My after return.
     *
     * @param joinPoint the join point
     */
    @AfterReturning("pointCut()")
    public void myAfterReturn(JoinPoint joinPoint){
        System.out.println("------------");
        System.out.println("这是后置通知:日志开始打印..");
        System.out.println("目标类是:"+joinPoint.getTarget());
        System.out.println("目标类方法是:"+joinPoint.getSignature().getName());
    }

    /**
     * After throwing.
     *
     * @param e the e
     */
    @AfterThrowing(value = "pointCut()",throwing = "e")
    public void afterThrowing(Exception e){
        System.out.println("--------------");
        System.out.println("异常通知类型是"+e.getMessage());
        System.out.println("--------------");
    }

    /**
     * After.
     */
    @After("pointCut()")
    public void after(){
        System.out.println("------------");
        System.out.println("这是最终通知:日志开始打印..");
    }

    /**
     * Around object.
     *
     * @param joinPoint the join point
     * @return the object
     * @throws Throwable the throwable
     */
    @Around("pointCut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("------------");
        System.out.println("这是环绕通知前置:日志开始打印..");
        Object proceed = joinPoint.proceed();
        System.out.println("这是环绕通知后置:日志开始打印..");
        return proceed;
    }
}
